package cn.schoolwow.workflow.module.initial.flow;

import cn.schoolwow.quickdao.QuickDAO;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class InitialDatabaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickDAO quickDAO = flowContext.checkInstanceData(QuickDAO.class);

//        quickDAO.beforeAutomaticCreate("初始化工作流实例名称", d->{
//            Property property = d.getProperty(WorkFlowInstance.class, "name");
//            property.notNull = false;
//            if(!d.hasColumn(property.entity.tableName, property.column)){
//                d.createColumn(property.entity.tableName, property);
//            }
//            d.query(WorkFlowInstance.class)
//                    .joinTable(WorkFlowDefinition.class, "definitionId", "id")
//                    .done()
//                    .addRawUpdate("name = t1.name")
//                    .execute()
//                    .update();
//            property.notNull = true;
//            d.rawUpdate("alter table "+property.entity.tableName+" alter column "+property.column+" set not null");
//        });
    }

    @Override
    public String name() {
        return "初始化数据库";
    }
}
